package com.simpleNews.LatestNews;

import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;

public class TTSObject {

	private TextToSpeech tts;

	public TTSObject(Context context) {
		TTSListener ttslListener = new TTSListener();
		tts = new TextToSpeech(context, ttslListener);
	}

	void Speak(String s) {
		if (tts.isSpeaking())
			tts.stop();

		if (s != null && s != "") {
			tts.speak(s, TextToSpeech.QUEUE_FLUSH, null);
		}
	}

	public void Shutdown() {
		if (tts != null) {
			tts.stop();
			tts.shutdown();
		}
	}
}

class TTSListener implements TextToSpeech.OnInitListener {

	@Override
	public void onInit(int status) {
		// TODO Auto-generated method stub
		if (status == TextToSpeech.SUCCESS) {

			// int result = tts.setLanguage(Locale.US);

			// if (result == TextToSpeech.LANG_MISSING_DATA
			// || result == TextToSpeech.LANG_NOT_SUPPORTED) {
			// Log.e("TTS", "This Language is not supported");
			// } else {

			// }

		} else {
			Log.e("TTS", "Initilization Failed!");
		}
	}

}
